package cn.kgc.service.impl;

import cn.kgc.entity.User;
import cn.kgc.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UserService implements cn.kgc.service.UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public List<User> getAllUser() {
        return userMapper.selectAll();
    }

    @Override
    public User getUserById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateByPrimaryKey(user);
    }

    @Override
    public void deleteUser(Integer id) {
        userMapper.deleteByPrimaryKey(id);

    }

    @Override
    public Integer countByName(String name) {
        int count = userMapper.selectCount(User.builder().username(name).build());
        return count;
    }

    @Override
    public List<User> getUserList(Integer pageNO, Integer pageSize) {
        PageHelper.startPage(pageNO,pageSize);
        return userMapper.selectAll();
    }
}
